package com.cjjd.c.feature.mine.hkb;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.bean.ExchangeRecordsBean;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.CustomerHkGoldBean;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.ListResult;
import com.cjjd.c.http.CallbackImpl;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;
import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/15.
 * <p/>
 * 描  述：我的好客币
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class HkbFragment extends BaseSwipeRefreshFragment {

    private TextView textView;

    @Override
    public Object getTitleString() {
        return "我的好客币";
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {
        ListResult<ExchangeRecordsBean> r=(ListResult<ExchangeRecordsBean>)response.body().getData();

        List<ExchangeRecordsBean> list=r.dataList;

        myBaseAdapter.setData(list);
        myBaseAdapter.notifyDataSetChanged();
    }

    private TextView textView_hknum;
    @Override
    protected void initView() {
        super.initView();
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_header_hkb, null);


//        textView = new TextView(mContext);
//        textView.setText("没有更多记录啦~");
//        textView.setGravity(Gravity.CENTER);
//        textView.setTextColor(getResources().getColor(R.color.textColorNomal));
//        textView.setPadding(30, 30, 30, 30);
        listBase.addHeaderView(view);
//        listBase.addFooterView(textView);
        textView_hknum=(TextView)view.findViewById(R.id.hknum);
        getHKBnum();
        listBase.setDivider(null);

    }

    private String hkGoldNum;
    private void getHKBnum(){

        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));

        service.getCustomerHkGold(JsonUtils.convertParam("getCustomerHkGold", h1)).enqueue(new CallbackImpl<CustomerHkGoldBean>() {
            @Override
            public void responseSuccess(Call<HttpResult<CustomerHkGoldBean>> call, Response<HttpResult<CustomerHkGoldBean>> response) {
                hkGoldNum=response.body().data.hkGoldNum;
                textView_hknum.setText(hkGoldNum);
            }
        });

    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new HkbAdapter(mContext);
    }

    @Override
    public Call<HttpResult> getCall() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        h1.put("nowPage", PAGE + "");
        h1.put("pageShow", PAGE_SIZE + "");

        return service.getExchangeRecords(JsonUtils.convertParam("getExchangeRecords", h1));

    }

}
